package com.ruoyi.common.constant;

import java.util.HashMap;
import java.util.Map;

/**
 * 机器常量信息
 * 
 * @author gonianer
 */
public class HostConstant
{
    /**
     * 主机状态
     */
    public static final String STATUS_SUBMIT="submit";
    public static final String STATUS_NORMAL="normal";
    public static final String STATUS_ONLINE="online";
    public static final String STATUS_DELETED="deleted";

    public static final String JWAGENT_USER="jwagent";
    public static final String JWAGENT_TEMP="/tmp/jwkmn";

    public static final String JWAGENT_AVAILABLE="available";
    public static final String JWAGENT_RESTARTING="restarting";
    public static final String JWAGENT_STOPPING="stopping";
    public static final String JWAGENT_REINSTALLING="reinstalling";
    public static final String JWAGENT_OFFLINE="offline";

    public static final Map<String, Map<String,String>> HOST_METRICS = new HashMap(){{
        //Linux 系统负载
        put("node_load", new HashMap(){{
                put("node_load1","avg(node_load1{exported_job='host_ip'})");
                put("node_load5","avg(node_load5{exported_job='host_ip'})");
                put("node_load15","avg(node_load15{exported_job='host_ip'})");
        }});
        //Linux CUP使用率
        put("node_cpu", new HashMap(){{
            put("cpu_percent","100 * (1 - sum(rate(node_cpu_seconds_total{exported_job='host_ip',mode='idle'}[interval])) / count(count(node_cpu_seconds_total{exported_job='host_ip'}) by (cpu)))");
        }});
        //Linux IOPS
        put("node_iops", new HashMap(){{
            put("read","avg(rate(node_disk_reads_completed_total{exported_job='host_ip'}[interval]))");
            put("write","avg(rate(node_disk_writes_completed_total{exported_job='host_ip'}[interval]))");
        }});
        //Linux IO 耗时
        put("node_iocost", new HashMap(){{
            put("read","1000000 * avg(rate(node_disk_read_time_seconds_total{exported_job='host_ip'}[interval]))");
            put("write","1000000 * avg(rate(node_disk_write_time_seconds_total{exported_job='host_ip'}[interval]))");
        }});
        //Linux IO 吞吐量
        put("node_iovol", new HashMap(){{
            put("read","avg(rate(node_disk_read_bytes_total{exported_job='host_ip'}[interval]) ) / 1048576");
            put("write","avg(rate(node_disk_written_bytes_total{exported_job='host_ip'}[interval]) ) / 1048576");
        }});
        //Linux 网络吞吐率
        put("node_network", new HashMap(){{
            put("send","avg(rate(node_network_transmit_bytes_total{exported_job='host_ip'}[interval]))/ 1048576");
            put("receive","avg(rate(node_network_receive_bytes_total{exported_job='host_ip'}[interval]))/ 1048576");
        }});
        //Linux 内存
        put("node_memory", new HashMap(){{
            put("memory_used","(avg(node_memory_MemTotal_bytes{exported_job='host_ip'}) " +
                    "- avg(node_memory_MemFree_bytes{exported_job='host_ip'}) " +
                    "- avg(node_memory_Cached_bytes{exported_job='host_ip'}) " +
                    "- avg(node_memory_Buffers_bytes{exported_job='host_ip'})) / 1073741824");
            put("memory_buffers","avg(node_memory_Buffers_bytes{exported_job='host_ip'})/ 1073741824");
            put("memory_free","avg(node_memory_MemFree_bytes{exported_job='host_ip'})/ 1073741824");
            put("memory_cached","avg(node_memory_Cached_bytes{exported_job='host_ip'})/ 1073741824");
        }});
        //Linux 磁盘
        put("node_disk", new HashMap(){{
            put("disk_used","100 - (avg(label_replace(node_filesystem_free_bytes{exported_job='host_ip',fstype!='tmpfs'}, \"metric_name\", \"$1\", \"device\", \"(.*)\")) by (metric_name) * 100) " +
                    "/ avg(label_replace(node_filesystem_size_bytes{exported_job='host_ip',fstype!='tmpfs'}, \"metric_name\", \"$1\", \"device\", \"(.*)\")) by (metric_name)");
        }});
    }};

}
